import pandas as pd
from tkinter.filedialog import askopenfilename
import FindData
from Compute import EstimateEigenvalues, TrueThickness, AngularDifference, PointAPrediction, TrueInclination


class ExcelReader:
    def __init__(self):
        self.file_path = self.select_file()
        if not self.file_path:
            raise ValueError("请选择一个有效的文件")
        self.data = self.read_data()

    def select_file(self):
        #选择Excel文件
        self.file_path = askopenfilename(filetypes=[("Excel files", "*.xlsx *.xls")])
        return self.file_path

    def read_data(self):
        #读取Excel文件中的数据
        if not self.file_path:
            raise ValueError("请选择一个有效的文件")

        # 读取指定范围的数据
        data = pd.read_excel(self.file_path, usecols="B:M", skiprows=10, nrows=1044)
        return data


# 示例用法
if __name__ == "__main__":
    reader = ExcelReader()
    print(reader.data)
    find = FindData.ExcelFinder(reader.data)
    data1 = find.findData(40)
    ee1 = EstimateEigenvalues(data1)
    excelData1 = ee1.estimateEigenvalues(40)
    data2 = find.findData(50)
    ee2 = EstimateEigenvalues(data2)
    excelData2 = ee2.estimateEigenvalues(50)
    tt = TrueThickness()
    trueThickness = tt.trueThickness(excelData1, excelData2, 15, True)
    print(trueThickness)
    trueThickness1 = tt.trueThickness(excelData1, excelData2, 15, False)
    print(trueThickness1)
    ad = AngularDifference()
    angularDifference1 = ad.angularDifference(99, 90, 5, 1, True)
    angularDifference2 = ad.angularDifference(99, 90, 5, 1, False)
    print(angularDifference1)
    print(angularDifference2)
    PA = PointAPrediction()
    pointAPrediction1 = PA.pointAPrediction(224, 4, 4027, 310, True)
    pointAPrediction2 = PA.pointAPrediction(224, 4, 4027, 310, False)
    print(pointAPrediction1)
    print(pointAPrediction2)
    ti = TrueInclination()
    trueInclination1 = ti.trueInclination(294, 717, 3, True)
    trueInclination2 = ti.trueInclination(294, 717, 3, False)
    print(trueInclination1)
    print(trueInclination2)

